﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Guard.cs" company="">
//   
// </copyright>
// <summary>
//   The guard.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace XRay.Library.Helpers
{
    #region

    using System;
    using System.Diagnostics;

    #endregion

    /// <summary>
    ///     The guard.
    /// </summary>
    public static class Guard
    {
        #region Public Methods and Operators

        /// <summary>
        /// The argument out of range.
        /// </summary>
        /// <param name="days">
        /// The days.
        /// </param>
        /// <param name="smallest">
        /// The smallest.
        /// </param>
        /// <param name="largest">
        /// The largest.
        /// </param>
        /// <param name="argumentName">
        /// The argument name.
        /// </param>
        /// <exception cref="ArgumentOutOfRangeException">
        /// </exception>
        public static void ArgumentOutOfRange(int days, int smallest, int largest, string argumentName)
        {
            if (days < smallest || days > largest)
            {
                throw new ArgumentOutOfRangeException(argumentName, "Days can be between 1 and 365.");
            }
        }

        #endregion

        #region Methods

        /// <summary>
        /// The argument not null.
        /// </summary>
        /// <param name="value">
        /// The value.
        /// </param>
        /// <param name="argumentName">
        /// The argument name.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// </exception>
        [DebuggerStepThrough]
        internal static void ArgumentNotNull(object value, string argumentName)
        {
            if (value == null)
            {
                throw new ArgumentNullException(argumentName);
            }
        }

        /// <summary>
        /// The argument not null or empty.
        /// </summary>
        /// <param name="value">
        /// The value.
        /// </param>
        /// <param name="argumentName">
        /// The argument name.
        /// </param>
        /// <exception cref="ArgumentOutOfRangeException">
        /// </exception>
        [DebuggerStepThrough]
        internal static void ArgumentNotNullOrEmpty(string value, string argumentName)
        {
            ArgumentNotNull(value, argumentName);

            if (string.IsNullOrEmpty(value))
            {
                throw new ArgumentOutOfRangeException(argumentName, "Parameter cannot be an empty string");
            }
        }

        #endregion
    }
}